package com.njtoyo.taxi.admin.security;

import com.njtoyo.taxi.admin.cache.CacheFinder;
import com.njtoyo.taxi.admin.rest.wrapper.Identity;
import com.njtoyo.taxi.entity.backend.AdminUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Optional;

/**
 * @Author Dell
 * @Date 2021/6/9 17:17
 */
@Component
public class AdminTokenParser {

    @Autowired
    private CacheFinder cacheFinder;

    public Identity parseToken(String token) {
        Identity identity = new Identity();
        Optional<AdminUser> optional = cacheFinder.findAdminById(Integer.valueOf(token));
        if(!optional.isPresent()){
            return null;
        }
        identity.setAdminUser(optional.get());
        identity.setIsExpired(false);
        return identity;
    }

}
